/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.hibernate.model;

import java.util.HashSet;
import java.util.Set;


import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import cn.org.rapid_framework.util.DateConvertUtils;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "ACCT_USER")
public class AcctUser extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "AcctUser";
	public static final String ALIAS_ID = "用户标识";
	public static final String ALIAS_USERNAME = "登录名，用户名";
	public static final String ALIAS_REALNAME = "真实姓名";
	public static final String ALIAS_PHONE = "手机号";
	public static final String ALIAS_EMAIL = "电子邮箱";
	public static final String ALIAS_STATUS = "状态：0启用 1关闭";
	public static final String ALIAS_CREATETIME = "注册时间";
	public static final String ALIAS_CATEGORY_FLAG = "是否开启人群属性 0关闭 1开启";
	public static final String ALIAS_PARENT_ID = "上一级别id";
	
	//date formats
	public static final String FORMAT_CREATETIME = DATE_FORMAT;
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * 用户标识       db_column: ID 
     */ 	
	
	private java.lang.Long id;
    /**
     * 登录名，用户名       db_column: USERNAME 
     */ 	
	@NotBlank @Length(max=45)
	private java.lang.String username;
	
	@NotBlank @Length(max=100)
	private java.lang.String password;
    /**
     * 真实姓名       db_column: REALNAME 
     */ 	
	@NotBlank @Length(max=45)
	private java.lang.String realname;
    /**
     * 手机号       db_column: PHONE 
     */ 	
	@Length(max=45)
	private java.lang.String phone;
    /**
     * 电子邮箱       db_column: EMAIL 
     */ 	
	@Length(max=100)
	private java.lang.String email;
    /**
     * 状态：0启用 1关闭       db_column: STATUS 
     */ 	
	
	private java.lang.Integer status;
    /**
     * 注册时间       db_column: CREATETIME 
     */ 	
	@NotNull 
	private java.util.Date createtime;
    /**
     * 是否开启人群属性 0关闭 1开启       db_column: CATEGORY_FLAG 
     */ 	
	
	private java.lang.Integer categoryFlag;

    /**
     * 池标识       db_column:POOL_ID 
     */ 	
	@NotNull 
	private java.lang.Long poolId;
	//columns END


	/**
	 * 角色名
	 */
	@Transient
	private java.lang.String roleName;
	  
	public AcctUser(){
	}

	public AcctUser(
		java.lang.Long id
	){
		this.id = id;
	}

	

	public void setId(java.lang.Long value) {
		this.id = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 19)
	public java.lang.Long getId() {
		return this.id;
	}
	
	@Column(name = "USERNAME", unique = false, nullable = false, insertable = true, updatable = true, length = 45)
	public java.lang.String getUsername() {
		return this.username;
	}
	
	public void setUsername(java.lang.String value) {
		this.username = value;
	}
	
	@Column(name = "PASSWORD", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	public java.lang.String getPassword() {
		return password;
	}
	
	public void setPassword(java.lang.String password) {
		this.password = password;
	}
	
	@Column(name = "POOL_ID", unique = false, nullable = false, insertable = true, updatable = true, length = 19)
	public java.lang.Long getPoolId() {
		return this.poolId;
	}
	
	public void setPoolId(java.lang.Long value) {
		this.poolId = value;
	}
	
	@Column(name = "REALNAME", unique = false, nullable = false, insertable = true, updatable = true, length = 45)
	public java.lang.String getRealname() {
		return this.realname;
	}
	
	public void setRealname(java.lang.String value) {
		this.realname = value;
	}
	
	@Column(name = "PHONE", unique = false, nullable = true, insertable = true, updatable = true, length = 45)
	public java.lang.String getPhone() {
		return this.phone;
	}
	
	public void setPhone(java.lang.String value) {
		this.phone = value;
	}
	
	@Column(name = "EMAIL", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
	public java.lang.String getEmail() {
		return this.email;
	}
	
	public void setEmail(java.lang.String value) {
		this.email = value;
	}
	
	@Column(name = "STATUS", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
	public java.lang.Integer getStatus() {
		return this.status;
	}
	
	public void setStatus(java.lang.Integer value) {
		this.status = value;
	}
	
	@Transient
	public String getCreatetimeString() {
		return DateConvertUtils.format(getCreatetime(), FORMAT_CREATETIME);
	}
	public void setCreatetimeString(String value) {
		setCreatetime(DateConvertUtils.parse(value, FORMAT_CREATETIME,java.util.Date.class));
	}
	
	@Column(name = "CREATETIME", unique = false, nullable = false, insertable = true, updatable = true, length = 0)
	public java.util.Date getCreatetime() {
		return this.createtime;
	}
	
	public void setCreatetime(java.util.Date value) {
		this.createtime = value;
	}
	
	@Column(name = "CATEGORY_FLAG", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
	public java.lang.Integer getCategoryFlag() {
		return this.categoryFlag;
	}
	
	public void setCategoryFlag(java.lang.Integer value) {
		this.categoryFlag = value;
	}
	
	private Set<AcctUserRole> acctUserRoles = new HashSet<AcctUserRole>(0);
	public void setAcctUserRoles(Set<AcctUserRole> acctUserRole){
		this.acctUserRoles = acctUserRole;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "acctUser")
	public Set<AcctUserRole> getAcctUserRoles() {
		return acctUserRoles;
	}

	private AcctPool acctPool;
	public void setAcctPool(AcctPool acctPool){
		this.acctPool = acctPool;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "POOL_ID",nullable = false, insertable = false, updatable = false) 
	})
	public AcctPool getAcctPool() {
		return acctPool;
	}
	

	
	@Override
	public String toString() {
		return "AcctUser [id=" + id + ", username=" + username + ", password="
				+ password + ", realname=" + realname + ", phone=" + phone
				+ ", email=" + email + ", status=" + status + ", createtime="
				+ createtime + ", categoryFlag=" + categoryFlag + ", poolId="
				+ poolId + ", roleName=" + roleName + ", acctUserRoles="
				+ acctUserRoles + ", acctPool=" + acctPool + "]";
	}

	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof AcctUser == false) return false;
		if(this == obj) return true;
		AcctUser other = (AcctUser)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "用户表";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return getUsername();
	}

	@Transient
    public java.lang.String getRoleName() {
        return roleName;
    }

	@Transient
    public void setRoleName(java.lang.String roleName) {
        this.roleName = roleName;
    }
}

